<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公司管理</title>
<!--导入各种支持  -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	var url;
	/* 启动自动查询所有公司信息 */
	function searchEmployee() {
		$("#dg").datagrid('load', {
			"name" : $("#s_name").val()
		});
	}

	//添加公司信息
	function openAddEmployeeDialog() {
		resetValue();
		$("#employeeForm").dialog("open").dialog("setTitle", "添加公司");
		url = "${pageContext.request.contextPath}/company/save.do";
	}
	//保存公司信息到后台
	function saveEmployee() {
		$("#fm").form("submit", {
			url : url,
			onSubmit : function() {
				return $(this).form("validate");
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.success) {
					$.messager.alert("系统提示", "保存成功！");
					resetValue();
					$("#employeeForm").dialog("close");
					$("#dg").datagrid("reload");
				} else {
					$.messager.alert("系统提示", "保存失败！");
					return;
				}
			}
		});
	}
	//更新公司信息
	function openUpdateEmployeeDialog() {
		var selectedRows = $("#dg").datagrid("getSelections");
		if (selectedRows.length != 1) {
			$.messager.alert("系统提示", "请选择一个要修改的公司!");
			return;
		}
		var row = selectedRows[0];
		$("#employeeForm").dialog("open").dialog("setTitle", "修改公司信息");
		$("#fm").form("load", row);
		url = "${pageContext.request.contextPath}/company/save.do?id=" + row.id;
	}

	//重置对话框数据为空
	function resetValue() {
		$("#name").val("");
		$("#id").val("");
		$("#father").val("");

	}
	//关闭对话框
	function closeEmployeeDialog() {
		$("#employeeForm").dialog("close");
		resetValue();
	}
	//删除员工
	function deleteEmployee() {
		var selectRows = $("#dg").datagrid("getSelections");
		if (selectRows.length == 0) {
			$.messager.alert("系统提示", "请选择需要删除的行数据！");
			return;
		}
		var strIds = [];
		for (var i = 0; i < selectRows.length; i++) {
			strIds.push(selectRows[i].id);
		}
		var ids = strIds.join(",");
		$.messager.confirm("系统提示", "您确认要删除这<font color=red>"
				+ selectRows.length + "</font>条数据吗？", function(r) {
			if (r) {
				$.post("${pageContext.request.contextPath}/company/delete.do",
						{
							ids : ids
						}, function(result) {
							if (result.success) {
								$.messager.alert("系统提示", "数据已成功删除！");
								$("#dg").datagrid("reload");
							} else {
								$.messager.alert("系统提示", "删除失败,请联系管理员！");
							}
						}, "json");
			}
		});
	}
</script>
</head>
<body style="margin: 1px">
	<table id="dg" title="人员管理" class="easyui-datagrid" fitColumns="true"
		pagination="true" rownumbers="true"
		url="${pageContext.request.contextPath}/company/list.do" fit="true"
		toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<th field="id" width="20" align="center">公司id</th>
				<th field="name" width="30" align="center">公司名称</th>
				<th field="father" width="30" align="center">父级公司</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openAddEmployeeDialog()"
				class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a> <a
				href="javascript:openUpdateEmployeeDialog()"
				class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a><a
				href="javascript:deleteEmployee()" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			&nbsp;公司名&nbsp;<input type="text" id="s_name" size="20"
				onkeydown="if(event.keyCode==13) searchBlog()" /> <a
				href="javascript:searchEmployee()" class="easyui-linkbutton"
				iconCls="icon-search" plain="true">搜索</a>
		</div>
	</div>
	<div id="employeeForm" class="easyui-dialog"
		style="width: 500px; height: 680px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<form id="fm" method="post">
			<table cellspacing="8px">
				<tr>
					<td>公司名称：</td>
					<td><input type="text" id="name" name="name"
						class="easyui-validatebox" required="true" /></td>
				</tr>


				<tr>
					<td>父级公司：</td>
					<td><input type="text" id="father" name="father" /></td>
				</tr>


			</table>
		</form>
	</div>

	<div id="dlg-buttons">
		<a href="javascript:saveEmployee()" class="easyui-linkbutton"
			iconCls="icon-ok">保存</a> <a href="javascript:closeEmployeeDialog()"
			class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
</body>
</html>